package com.southpark.system.managers
{
	import com.southpark.framework.managers.ErrorManager;
	import com.southpark.system.interfaces.managers.IApplicationManager;
	import com.southpark.system.interfaces.managers.IAssetManager;
	
	import flash.utils.Dictionary;
	

	
	public class AssetManager implements IAssetManager
	{	
		
		public function AssetManager(applicationManager:IApplicationManager)
		{
			this.applicationManager = applicationManager;
			createAssetList();
		}
		
		
		/**
		 * 
		 */
		private var applicationManager:IApplicationManager;
		private var assetDictionary:Dictionary;
		
		private function createAssetList():void
		{
			assetDictionary = new Dictionary();
			
			for each (var item:Array in applicationManager.assetMap)
			{
				defineAsset(item[0],item[1]);
			};
		} 
		
		private function defineAsset(assetInterface:Class,assetClass:Class):void
		{	
		 	if (assetDictionary[assetInterface])
		 	{
		 		ErrorManager.throwError(ErrorManager.DUPLICATE_DEFINITION,this);
		 		return;
		 	};
		 
		 	assetDictionary[assetInterface] = assetClass;
		}
		 
		public function getAsset(assetInterface:Class):Class
		{
			if (!assetDictionary[assetInterface]) 
			{
				applicationManager.infoManager.showApplicationError("Asset " + Class(assetInterface).toString() + " is not included");
				return null;
			};
			
			return assetDictionary[assetInterface];
		}
		
		
	}
}